package util;

import crossover.*;
import mutation.*;
import selection.*;
import localSearch.*;

public class GAOperationsConfig {

	private static Crossover crossoverStrategy = null;
	public static Crossover getCrossoverStrategy() {

		if (GAOperationsConfig.crossoverStrategy != null)
			return GAOperationsConfig.crossoverStrategy;

		String strategy = GAConfig.CrossoverStrategy;

		try {
			GAOperationsConfig.crossoverStrategy = (Crossover) Class.forName(
					strategy).newInstance();
			return GAOperationsConfig.crossoverStrategy;
		} catch (Exception ex) {
			throw new RuntimeException(
					"CrossoverStrategy could not be determined, verify the configuration file",
					ex);
		}
	}
	private static Mutation mutationChangeValueStrategy = null;
	public static Mutation getMutationChangeValueStrategy() {

		if (GAOperationsConfig.mutationChangeValueStrategy != null)
			return GAOperationsConfig.mutationChangeValueStrategy;

		String strategy = "mutation.ChangeInputValue";

		try {
			GAOperationsConfig.mutationChangeValueStrategy = (Mutation) Class.forName(
					strategy).newInstance();
			return GAOperationsConfig.mutationChangeValueStrategy;
		} catch (Exception ex) {
			throw new RuntimeException(
					"mutation Change Value Strategy could not be determined, verify the configuration file",
					ex);
		}
	}
	private static Mutation mutationMuthodInsertStrategy = null;
	public static Mutation getMutationMethodInsertStrategy() {
		if (GAOperationsConfig.mutationMuthodInsertStrategy != null)
			return GAOperationsConfig.mutationMuthodInsertStrategy;

		String strategy = "mutation.InsertRandomMethodCall";
		try {
			GAOperationsConfig.mutationMuthodInsertStrategy = (Mutation) Class.forName(
					strategy).newInstance();
			return GAOperationsConfig.mutationMuthodInsertStrategy;
		} catch (Exception ex) {
			throw new RuntimeException(
					"mutation Muthod Insert Strategy could not be determined, verify the configuration file",
					ex);
		}
	}
	private static Mutation mutationMuthodDeleteStrategy = null;
	public static Mutation getMutationMethodDeleteStrategy() {
		if (GAOperationsConfig.mutationMuthodDeleteStrategy != null)
			return GAOperationsConfig.mutationMuthodDeleteStrategy;

		String strategy = "mutation.DeleteRandomMethodCall";
		try {
			GAOperationsConfig.mutationMuthodDeleteStrategy = (Mutation) Class.forName(
					strategy).newInstance();
			return GAOperationsConfig.mutationMuthodDeleteStrategy;
		} catch (Exception ex) {
			throw new RuntimeException(
					"mutation Muthod Delete Strategy could not be determined, verify the configuration file",
					ex);
		}
	}

	private static Selection    parentSelector       = null;
	public static Selection getParentSelector() {
		try {
			if (GAOperationsConfig.parentSelector != null)
				return GAOperationsConfig.parentSelector;

		String selector = "selection.TournamentSelection";
			
			GAOperationsConfig.parentSelector = (Selection) Class.forName(
					selector).newInstance();
			return GAOperationsConfig.parentSelector;
		} catch (Exception ex) {
			throw new RuntimeException(
					"ParentSelector could not be determined, verify the configuration file",
					ex);
		}

	}
	
	private static LocalSearch    localSearch       = null;	
	public static LocalSearch getLocalSearch() {
		if (GAOperationsConfig.localSearch != null)
			return GAOperationsConfig.localSearch;

		String strategy = "localSearch.HillClimbing";
		try {
			GAOperationsConfig.localSearch = (LocalSearch) Class.forName(strategy).newInstance();

			return GAOperationsConfig.localSearch;
		} catch (Exception ex) {
			throw new RuntimeException(
					"LocalSearch could not be determined, verify the configuration file",ex);
		}
	}

}
